-- EffectM
-- Create by panyl
-- 管理特效

module("EffectM", package.seeall);

-- 所有的道具信息
local effects = {};

-- 载入配置表
local _init = false;
local loadCsv = function()
    if _init then return end
    _init = true;

    -- 转换下effect信息表
    local effect_CSV = get_effect_CSV();
    for i = 1, #effect_CSV do
        local effectId = effect_CSV[i].effect_id;
        effects[effectId] = effect_CSV[i];
        
        -- 解析特效偏移
        parseActionFrameRange(effects[effectId]);
    end

    effect_CSV = {};
end

-- 模块初始化
function init()
    loadCsv();
end

-- 检索特效信息
function query(effectId, path)
    local m = effects[effectId]
    
    if not m or path == "" or not path then
        return m
    end
    
    return m[path]
end

-- 解析特效偏移
function parseActionFrameRange(info)
    local offset = info.off_set;

    if offset ~= nil and offset ~= "" then
        local coords = string.explode(string.sub(offset, 2, -2), ",");
        info.off_set = { tonumber(coords[1]), tonumber(coords[2]) };
    else
        info.off_set = { 0, 0 };
    end

    return info;
end


